package com.example.ppp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.ppp.entity.Count;
import com.example.ppp.entity.User;
import com.example.ppp.mapper.UserMapper;
import com.example.ppp.service.CountService;
import com.example.ppp.mapper.CountMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author admin
 * @description 针对表【count】的数据库操作Service实现
 * @createDate 2023-05-18 14:58:27
 */
@Service
public class CountServiceImpl extends ServiceImpl<CountMapper, Count>
        implements CountService {

    @Autowired
    private CountMapper countMapper;
    @Autowired
    private UserMapper userMapper;

    @Override
    public void insertCounts() {
        long start = System.currentTimeMillis();
        List<Count> countList = new ArrayList<>();
        List<User> users = userMapper.selectList(null);
        int i = 0;
        if (users.size() > 0) {
            for (User user : users) {
                Count count = new Count();
                count.setUserId(user.getId());
                count.setTel("123456"+i);
                i+=1;
                countList.add(count);
            }
            countMapper.insertBatchSomeColumn(countList);
            long end = System.currentTimeMillis();
            System.out.println("一万条数据总耗时：" + (end - start) + "ms");
        }

    }

}




